package com.ext.demo21.controller;

import com.ext.demo21.entity.User;
import com.ext.demo21.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
public class testController {

    @Autowired
    private TestService service;

    @GetMapping("/user")
    public String getUser(){
        service.getUser(1);
        return "success";
    }

    @GetMapping("/get1")
    public String get1(Model model) {
        model.addAttribute("get", "get");
        log.info("good-----------------");
        return "success";
    }

    @GetMapping("/get2/{msg}")
    public Map<String, Object> get2(@PathVariable("msg") String msg) {
        Map<String, Object> map = new HashMap<>();
        map.put("msg", msg);
        return map;
    }

    @GetMapping("/get3")
    public  String  get3(String msg){
        return msg;
    }

    @PostMapping("/get4")
    public  String get4(@RequestBody User user){
        if(user  !=null) {
            log.info(user.getName()+"---"+user.getId());
            return "good";
        }
        else return "false";
    }
}
